﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace DALL.SysManage
{
   public class T_PUB_WEDDINGSYTLE
   {
       public T_PUB_WEDDINGSYTLE()
       { }
       #region  Method

       /// <summary>
       /// 增加一条数据
       /// </summary>
       public int Add(Model.SysManage.T_PUB_WEDDINGSYTLE model)
       {
           StringBuilder strSql = new StringBuilder();
           strSql.Append("insert into T_PUB_WEDDINGSYTLE(");
           strSql.Append("NAME,REMARK)");

           strSql.Append(" values (");
           strSql.Append("@NAME,@REMARK)");
           strSql.Append(";select @@IDENTITY");
           Database db = DatabaseFactory.CreateDatabase();
           DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
           db.AddInParameter(dbCommand, "NAME", DbType.String, model.NAME);
           db.AddInParameter(dbCommand, "REMARK", DbType.String, model.REMARK);
           int result;
           object obj = db.ExecuteScalar(dbCommand);
           if (!int.TryParse(obj.ToString(), out result))
           {
               return 0;
           }
           return result;
       }
       /// <summary>
       /// 更新一条数据
       /// </summary>
       public bool Update(Model.SysManage.T_PUB_WEDDINGSYTLE model)
       {
           StringBuilder strSql = new StringBuilder();
           strSql.Append("update T_PUB_WEDDINGSYTLE set ");
           strSql.Append("NAME=@NAME,");
           strSql.Append("REMARK=@REMARK");
           strSql.Append(" where ID=@ID ");
           Database db = DatabaseFactory.CreateDatabase();
           DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
           db.AddInParameter(dbCommand, "ID", DbType.Int32, model.ID);
           db.AddInParameter(dbCommand, "NAME", DbType.String, model.NAME);
           db.AddInParameter(dbCommand, "REMARK", DbType.String, model.REMARK);
           int rows = db.ExecuteNonQuery(dbCommand);

           if (rows > 0)
           {
               return true;
           }
           else
           {
               return false;
           }
       }

       /// <summary>
       /// 删除一条数据
       /// </summary>
       public bool Delete(int ID)
       {

           StringBuilder strSql = new StringBuilder();
           strSql.Append("delete from T_PUB_WEDDINGSYTLE ");
           strSql.Append(" where ID=@ID ");
           Database db = DatabaseFactory.CreateDatabase();
           DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
           db.AddInParameter(dbCommand, "ID", DbType.Int32, ID);
           int rows = db.ExecuteNonQuery(dbCommand);

           if (rows > 0)
           {
               return true;
           }
           else
           {
               return false;
           }
       }

       /// <summary>
       /// 得到一个对象实体
       /// </summary>
       public Model.SysManage.T_PUB_WEDDINGSYTLE GetModel(int ID)
       {

           StringBuilder strSql = new StringBuilder();
           strSql.Append("select ID,NAME,REMARK from T_PUB_WEDDINGSYTLE ");
           strSql.Append(" where ID=@ID ");
           Database db = DatabaseFactory.CreateDatabase();
           DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
           db.AddInParameter(dbCommand, "ID", DbType.Int32, ID);
           Model.SysManage.T_PUB_WEDDINGSYTLE model = null;
           using (IDataReader dataReader = db.ExecuteReader(dbCommand))
           {
               if (dataReader.Read())
               {
                   model = ReaderBind(dataReader);
               }
           }
           return model;
       }

       /// <summary>
       /// 获得数据列表
       /// </summary>
       public DataSet GetList(string strWhere)
       {
           StringBuilder strSql = new StringBuilder();
           strSql.Append("select ID,NAME,REMARK ");
           strSql.Append(" FROM T_PUB_WEDDINGSYTLE ");
           if (strWhere.Trim() != "")
           {
               strSql.Append(" where " + strWhere);
           }
           Database db = DatabaseFactory.CreateDatabase();
           return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
       }


       /// <summary>
       /// 获得数据列表（比DataSet效率高，推荐使用）
       /// </summary>
       public List<Model.SysManage.T_PUB_WEDDINGSYTLE> GetListArray(string strWhere)
       {
           StringBuilder strSql = new StringBuilder();
           strSql.Append("select ID,NAME,REMARK ");
           strSql.Append(" FROM T_PUB_WEDDINGSYTLE ");
           if (strWhere.Trim() != "")
           {
               strSql.Append(" where " + strWhere);
           }
           List<Model.SysManage.T_PUB_WEDDINGSYTLE> list = new List<Model.SysManage.T_PUB_WEDDINGSYTLE>();
           Database db = DatabaseFactory.CreateDatabase();
           using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
           {
               while (dataReader.Read())
               {
                   list.Add(ReaderBind(dataReader));
               }
           }
           return list;
       }


       /// <summary>
       /// 对象实体绑定数据
       /// </summary>
       public Model.SysManage.T_PUB_WEDDINGSYTLE ReaderBind(IDataReader dataReader)
       {
           Model.SysManage.T_PUB_WEDDINGSYTLE model = new Model.SysManage.T_PUB_WEDDINGSYTLE();
           object ojb;
           ojb = dataReader["ID"];
           if (ojb != null && ojb != DBNull.Value)
           {
               model.ID = (int)ojb;
           }
           model.NAME = dataReader["NAME"].ToString();
           model.REMARK = dataReader["REMARK"].ToString();
           return model;
       }

       #endregion  Method
   }
}
